package com.cf.r1032_ak;

import java.io.*;

public class b {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(br.readLine().trim());
            String s = br.readLine().trim();
            int[] cnt = new int[26];
            for (int i = 0; i < n; i++) cnt[s.charAt(i) - 'a']++;
            boolean ans = false;
            for (int ch = 0; ch < 26; ch++) {
                if (cnt[ch] >= 3) {
                    ans = true;
                    break;
                } else if (cnt[ch] == 2) {
                    if (!(s.charAt(0) - 'a' == ch && s.charAt(n - 1) - 'a' == ch)) {
                        ans = true;
                        break;
                    }
                }
            }
            out.println(ans ? "YES" : "NO");
        }
        out.flush();
        out.close();
        br.close();
    }
}
